<template>
  <div class="app-container">
    <van-nav-bar title="投票" left-arrow @click-left="$router.push('/home')" />
    <div class="content-box">
      <el-input v-model="form.activityName" placeholder="搜索你想要找到的投票" @change="getData" />
      <img class="banner" :src="require('@/assets/images/vote/banner.png')" alt="">
      <div class="list-box">
        <div class="list-title">发现投票</div>
        <div class="list-content" v-if="listItemList.length">
          <div class="list-item" v-for="(item, index) in listItemList" :key="index" @click="toDetail(item)">
            <div class="item-cover">
              <img class="cover-img" :src="item.activityImage">
            </div>
            <div class="item-label-box">
              <div class="item-label">{{ item.activityName }}</div>
              <div class="item-tip">
                {{ dayjs(item.startTime).format('YYYY年MM月DD日') }}—{{ dayjs(item.endTime).format('YYYY年MM月DD日') }}
              </div>
            </div>
          </div>
        </div>
        <div class="empty" v-else>暂无数据</div>
      </div>
    </div>
  </div>
</template>

<script>
import * as api from '@/api/activityManger/index.js';
import dayjs from 'dayjs';

export default {
  name: 'VoteIndex',
  data() {
    return {
      form: { activityName: '', activityTypeId: 1, pageNum: 1, pageSize: 10 },
      listItemList: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    dayjs,
    getData() {
      api.getActivityList({ ...this.form }).then((res) => {
        this.listItemList = res.rows;
      });
    },
    toDetail(item) {
      this.$router.push({ name: 'VoteDetail2', query: { activityId: item.id } });
    },
  },
};
</script>

<style lang="scss" scoped>
@import '@/assets/styles/mixin.scss';

.content-box {
  width: calc(100% - 30px);
  height: calc(100% - 70px);
  padding: 10px 15px;
  display: flex;
  flex-direction: column;
}

::v-deep .el-input__inner {
  border-radius: 20px;
}

.banner {
  width: 100%;
  margin: 10px 0;
}

@include list-box-style;

.list-box {
  width: calc(100% - 30px);
  flex: 1;
}
</style>
